#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>

#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include "testutils.h"

/*
 * +1 buy
 * If not discard estate, +4 coins
 * Otherwise, gain estate
 */
void baron_test(void)
{
	int i, j;
	int choice1;
	int prev_coins;
	int prev_estate_count;
	int prev_baron_count;
	int prev_buys;
	struct gameState state;

	init_test_date(&state, 1);

	srand(time(NULL));

	for (i = 0; i < MAX_ITERATIONS; i++) {
		state.deckCount[0] = 50;
		for (j = 0; j < state.deckCount[0]; j++) {
			state.deck[0][j] = random_card();
		}

		state.handCount[0] = 5;
		for (j = 0; j < 4; j++) {
			state.hand[0][j] = random_card();
		}
		state.hand[0][4] = baron;

		prev_actions = state.numActions;
		prev_estate_count = card_count(state.hand[0], estate, state.handCount[0]);
		prev_baron_count = card_count(state.hand[0], baron, state.handCount[0]);

		choice1 = rand() % 2;
		prev_coins = state.coins;
		prev_buys = state.numBuys;

		baron_effect(&state, 0, choice1);

		assert(card_count(state.hand[0], baron, state.handCount[0]) == prev_baron_count - 1);
		assert(state.numBuys == prev_buys + 1);

		if (choice1) {
			assert(state.coins == prev_coins + 4);
			assert(card_count(state.hand[0], estate, state.handCount[0]) == prev_estate_count - 1);
		} else {
			assert(card_count(state.hand[0], estate, state.handCount[0]) == prev_estate_count + 1);
		}
	}
}

int main(int argc, char const *argv[])
{
	baron_test();
	return 0;
}